<?xml version="1.0" ?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:msxsl="urn:schemas-microsoft-com:xslt"
  exclude-result-prefixes="msxsl"
  version="1.0">
<xsl:import href="../Common/meta.xsl"/>
<xsl:output method="html" 
	doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" 
	doctype-public="-//W3C//DTD XHTML 1.0 Transitional//EN" />
<xsl:param name="lang" select="'chi'"/>
<xsl:param name="archive" select="'false'"/>
<xsl:param name="archmonth" select="10"/>
<xsl:param name="archyear" select="2008"/>
<xsl:param name="minitems" select="10"/>
<xsl:variable name="archdate" select="$archyear*12+$archmonth"/>
<xsl:variable name="headers" select="document(/news/header/@href)//header[@lang=$lang]"/>
<xsl:template match = "/">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
  <title>
    <xsl:call-template name="title" />
  </title>
  <xsl:call-template name="content-lang" />
  <link rel="stylesheet" type="text/css" media="screen" href="/css/default.css" />
  <link rel="stylesheet" type="text/css" media="screen" href="/css/news/news.min.css" />
  <link rel="stylesheet" type="text/css" media="print" href="/css/print.css" />
  <script type="text/javascript" src="/js/lib/jquery-1.5.1.min.js"></script>
  <script type="text/javascript" src="/js/lib/hoverIntent.min.js"></script>
  <script type="text/javascript" src="/js/lib/superfish.min.js"></script>
  <script type="text/javascript" src="/js/lib/jquery.cycle.all.min.js"></script>
  <script type="text/javascript" src="http://www.google-analytics.com/ga.js"></script>
  <script type="text/javascript">
    var pageTracker = _gat._getTracker("UA-3662766-1");
    pageTracker._initData();
    pageTracker._trackPageview();
  </script>
<xsl:if test="$archive='false'">
  <base  target="_parent" />
</xsl:if>

</head>
<body>
  <div id="News">
	  <xsl:call-template name="showheader" />
	  <xsl:apply-templates />
	  <xsl:call-template name="showfooter" />
  </div>
</body>
</html>
</xsl:template>

<xsl:template name="title">
  <xsl:choose>
    <xsl:when test="$archive='false'">
      <xsl:value-of select="$headers/title"/>
    </xsl:when>
    <xsl:otherwise>
      <xsl:value-of select="$headers/archive"/>
    </xsl:otherwise>
  </xsl:choose>
</xsl:template>  
  
<xsl:template name="showheader">
 <xsl:choose>
  <xsl:when test="$archive='false'">
    <p id="RSS"><a href="rss.xml" target="_parent">RSS</a></p>
  </xsl:when>
  <xsl:otherwise>
  </xsl:otherwise>
 </xsl:choose>
</xsl:template>

<xsl:template name="showfooter">
</xsl:template>

<xsl:template match="news">
 <table>
 <xsl:variable name="latest"> 
     <xsl:for-each select="article">
      <xsl:sort data-type="number" select="@year" order="descending"/>
      <xsl:sort data-type="number" select="@month" order="descending"/>
      <xsl:sort data-type="number" select="@day" order="descending"/>
      <xsl:if test="position()=1">
         <first><xsl:copy-of select="."/></first>
      </xsl:if>
      <xsl:if test="(position() &gt; 1) and (position() &lt;= $minitems)">
         <second><xsl:copy-of select="."/></second>
      </xsl:if>
     </xsl:for-each>
 </xsl:variable>
 <xsl:variable name="lfirst" select="msxsl:node-set($latest)/first/article"/>
 <xsl:variable name="lsecond" select="msxsl:node-set($latest)/second/article"/>
	
 <xsl:choose>
   <xsl:when test="$archive='false'">
    <!-- Find out the latest two items -->
<!--  <xsl:apply-templates select="article[@year*12+@month &gt;= $archdate or 
         not(parent::news/article/@year*12+parent::news/article/@month &gt; @year*12+@month)]">-->
     <xsl:apply-templates select="article[((@year*12+@month &gt;= $archdate) 
        or (@year = $lfirst/@year and @month=$lfirst/@month and @day=$lfirst/@day) 
        or (@year = $lsecond/@year and @month=$lsecond/@month and @day=$lsecond/@day)) and (@day>0)]">
      <xsl:sort data-type="number" select="@year" order="descending"/>
      <xsl:sort data-type="number" select="@month" order="descending"/>
      <xsl:sort data-type="number" select="@day" order="descending"/>
     </xsl:apply-templates>
   </xsl:when>
   <xsl:otherwise>
     <xsl:apply-templates select="article[(@year*12+@month &lt; $archdate) and not((@year = $lfirst/@year and @month=$lfirst/@month and @day=$lfirst/@day) or (@year = $lsecond/@year and @month=$lsecond/@month and @day=$lsecond/@day)) and (@day>0)]">
      <xsl:sort data-type="number" select="@year" order="descending"/>
      <xsl:sort data-type="number" select="@month" order="descending" />
      <xsl:sort data-type="number" select="@day" order="descending" />
     </xsl:apply-templates>
   </xsl:otherwise>
 </xsl:choose>
 </table>
 <xsl:if test="$archive='false'">
   <p class="more"><a href="newsarchive.html" target="_parent"><xsl:value-of select="$headers/archive"/></a></p>
 </xsl:if>
</xsl:template>

<xsl:template match="article">
  
  <xsl:variable name="i2">
    <xsl:choose>
       <xsl:when test="string(item[@lang=$lang])!=''">
          <xsl:copy-of select="item[@lang=$lang]/*|item[@lang=$lang]/text()"/>
       </xsl:when>
       <xsl:otherwise>
          <xsl:copy-of select="item[1]/*|item[1]/text()"/>
       </xsl:otherwise> 
    </xsl:choose>
  </xsl:variable>  
  <xsl:variable name="i" select="msxsl:node-set($i2)"/>
 <xsl:choose>
  <xsl:when test="$archive='false'">
    <tr>
      <th><xsl:value-of select="@day"/>/<xsl:value-of select="@month"/>/<xsl:value-of select="@year"/></th>
      <td><xsl:copy-of select="$i/*|$i/text()"/></td>
    </tr>
  </xsl:when>
  <xsl:otherwise>
    <tr>
      <th><xsl:value-of select="@day"/>/<xsl:value-of select="@month"/>/<xsl:value-of select="@year"/></th>
      <td><xsl:copy-of select="$i/*|$i/text()"/></td>
    </tr>
  </xsl:otherwise>
 </xsl:choose>
</xsl:template>

</xsl:stylesheet>
